//
//  Detail_VC.m
//  XiAnJMApp
//
//  Created by Kai Wang on 2017/5/22.
//  Copyright © 2017年 Kai Wang. All rights reserved.
//

#import "Detail_VC.h"
#import "Detail_Header_Cell.h"
#import "Detail_Pic_Cell.h"
#import "Tabbar_view.h"
#import "Common.h"

@interface Detail_VC ()
<
UITableViewDelegate,
UITableViewDataSource
>

@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)NSMutableArray*marr_Section;
@property(nonatomic, strong)NSMutableArray*marr_Data;

@property (nonatomic,strong)Tabbar_view * view_tabbar;

@end

@implementation Detail_VC

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setProperty];
    [self createUI];
    [self Create_Marr_Section];
}

#pragma mark==================setProperty======================
-(void)setProperty{
    _marr_Data=[[NSMutableArray alloc]init];
    
    self.view .backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.automaticallyAdjustsScrollViewInsets = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
        self.navigationController.navigationBar.clipsToBounds = NO;
    }
    _marr_Section=[[NSMutableArray alloc]init];
    self.title=@"详情";
    
}
-(void)createUI{
    self.view.backgroundColor=RGB(242, 242, 242);
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view).offset(0);
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(-50);
    }];

    _view_tabbar=[[Tabbar_view alloc]init];
    [self.view addSubview:_view_tabbar];
    [_view_tabbar mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.view.mas_bottom);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.mas_equalTo(50);
        
    }];
    
}


-(void)Create_Marr_Section{
    
    [_marr_Section removeAllObjects];
    
    
    
    CellModel* cell_model1 =[[CellModel alloc]init];
    cell_model1.reuseIdentifier = NSStringFromClass([Detail_Header_Cell class]);
    cell_model1.className=NSStringFromClass([Detail_Header_Cell class]);
    cell_model1.height = [Detail_Header_Cell computeHeight:nil];
    cell_model1.selectionStyle=UITableViewCellSelectionStyleNone;
    cell_model1.accessoryType=UITableViewCellAccessoryNone;
    
    /*
     * 传递参数
     */
    cell_model1.userInfo = nil;
    SectionModel *model0=[SectionModel sectionModelWithTitle:@"" cells:@[cell_model1]];
    model0.headerhHeight=0.0001;
    model0.footerHeight=10;
    [_marr_Section addObject:model0];

    
    CellModel* cell_model2 =[[CellModel alloc]init];
    cell_model2.reuseIdentifier = NSStringFromClass([Detail_Pic_Cell class]);
    cell_model2.className=NSStringFromClass([Detail_Pic_Cell class]);
    cell_model2.height = [Detail_Pic_Cell computeHeight:nil];
    cell_model2.selectionStyle=UITableViewCellSelectionStyleNone;
    cell_model2.accessoryType=UITableViewCellAccessoryNone;
    
    /*
     * 传递参数
     */
    cell_model2.userInfo = nil;
    SectionModel *model1=[SectionModel sectionModelWithTitle:@"" cells:@[cell_model2]];
    model1.headerhHeight=0.0001;
    model1.footerHeight=10;
    [_marr_Section addObject:model1];
    
    
    
    [_tableView reloadData];
    
}
#pragma mark tableView 代理相关
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _marr_Section.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    SectionModel *sm = _marr_Section[section];
    return sm.cells.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    SectionModel *sm = _marr_Section[section];
    return sm.headerhHeight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    SectionModel *sm = _marr_Section[section];
    return sm.footerHeight;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    SectionModel *sm = _marr_Section[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    
    return cm.height;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SectionModel *sm = _marr_Section[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cm.reuseIdentifier];
    if (!cell) {
        cell = [[NSClassFromString(cm.className) alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cm.reuseIdentifier];
    }
    cell.selectionStyle = cm.selectionStyle;
    
    
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];

}

@end
















































